import { inherit } from "../utils/common";
import { glLocation } from '../WebGLRenderer';
import {
  assignVertexAttrib1f,
} from '../WebGLRenderer/gl/gl-assign'
import { initVertexBuffer } from "../WebGLRenderer/gl/gl-buffer";
import Entity from "./Entity";
import { Point3d } from "./Point3d";
export function Line3d(startPt, endPt) {
  // if(! startPt instanceof Point3d
  // || ! endPt instanceof Point3d){
  //   throw new Error('[rcad]: Line3d params is error');
  // }
  this.startPt = startPt;
  this.endPt = endPt;
}
Line3d.prototype = inherit(Entity.prototype);
Line3d.prototype.constructor = Line3d;
Line3d.prototype.setStartPt = function (pt) {
  this.startPt = pt;
}
Line3d.prototype.setEndPt = function (pt) {
  this.endPt = pt;
}
Line3d.prototype.render = function (gl) {
  if(!gl) console.error('[rcad] render Line3d gl is null')
  let verticesArr = []
  verticesArr.push(this.startPt.x);
  verticesArr.push(this.startPt.y);
  verticesArr.push(this.startPt.z);
  verticesArr.push(this.endPt.x);
  verticesArr.push(this.endPt.y);
  verticesArr.push(this.endPt.z);
  let vertices = new Float32Array(verticesArr);
  initVertexBuffer(gl, glLocation.a_Position, vertices, 3, 0, 0);
  // 三角形不需要这个
  assignVertexAttrib1f(gl, glLocation.a_PointSize, 5)
  gl.drawArrays(gl.LINE_STRIP, 0, 2)
}